package com.lxk.server;

import com.lxk.server.biz.PersonServiceImpl;
import com.lxk.spi.inface.PersonService;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportFactory;

public class ThriftServer {

    public static void main(String[] args) {
        PersonServiceImpl personService = new PersonServiceImpl();
        PersonService.Processor processor = new PersonService.Processor<PersonService.Iface>( personService );
        TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory();
        TTransportFactory transportFactory = new TTransportFactory();
        try{
            TServerTransport transport = new TServerSocket(8099);
            TThreadPoolServer.Args tArgs = new TThreadPoolServer.Args(transport);
            tArgs.processor(processor);
            tArgs.protocolFactory(protocolFactory);
            tArgs.transportFactory(transportFactory);
            tArgs.minWorkerThreads(1);
            tArgs.maxWorkerThreads(10);
            TServer server = new TThreadPoolServer(tArgs);
            server.serve();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
